home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / WordBreakTable.java < prev    next >
Text File  |  1998-09-22  |  3KB  |  102 lines

  1. /*
  2.  * @(#)WordBreakTable.java    1.2 97/10/28
  3.  *
  4.  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  5.  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
  6.  *
  7.  * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  8.  *
  9.  *   The original version of this source code and documentation is copyrighted
  10.  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  11.  * materials are provided under terms of a License Agreement between Taligent
  12.  * and Sun. This technology is protected by multiple US and International
  13.  * patents. This notice and attribution to Taligent may not be removed.
  14.  *   Taligent is a registered trademark of Taligent, Inc.
  15.  *
  16.  * Permission to use, copy, modify, and distribute this software
  17.  * and its documentation for NON-COMMERCIAL purposes and without
  18.  * fee is hereby granted provided that this copyright notice
  19.  * appears in all copies. Please refer to the file "copyright.html"
  20.  * for further important copyright and licensing information.
  21.  *
  22.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  23.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  24.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  25.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  26.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  27.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  28.  *
  29.  */
  30.  
  31. package java.text;
  32.  
  33. /**
  34.  * This class implements a state transition table.
  35.  * After each transition, using the get method, the
  36.  * new state is returned along with information about
  37.  * the state change (ex. was it a "marked" transition").
  38.  * This class is internal only.
  39.  */
  40. final class WordBreakTable
  41. {
  42.     /**
  43.      * Construct a table using existing data.  See SentenceBreakBoundary and
  44.      * the other SimpleTextBoundary subclasses for examples.
  45.      * @param cols number of columns in the table
  46.      * @param data an encoded byte array containing state and transition data
  47.      */
  48.     public WordBreakTable(int cols, byte data[])
  49.     {
  50.         this.data = data;
  51.         this.cols = cols;
  52.     }
  53.  
  54.     /**
  55.      * Get the resulting state moving from oldState accepting input
  56.      * @param oldState current state
  57.      * @param input input
  58.      * @return int resulting state and transition data
  59.      */
  60.     public int get(int oldState, int input)
  61.     {
  62.         return data[(oldState & INDEX_MASK) * cols + input];
  63.     }
  64.  
  65.     /**
  66.      * Checks to see if the transition into the specified state was "marked"
  67.      * @param state the state as returned by get, initialState, or endState
  68.      * @return true if transition into state was marked.
  69.      */
  70.     public boolean isMarkState(int state)
  71.     {
  72.         return (state & MARK_MASK) != 0;
  73.     }
  74.  
  75.     /**
  76.      * Check is a state is the end state
  77.      * @param state the state to check
  78.      * @return true if state is an end state
  79.      */
  80.     public boolean isEndState(int state)
  81.     {
  82.         return (state & INDEX_MASK) == END_STATE;
  83.     }
  84.  
  85.     /**
  86.      * Get the start state
  87.      * @return the initial state
  88.      */
  89.     public int initialState()
  90.     {
  91.         return INITIAL_STATE;
  92.     }
  93.  
  94.     static final byte MARK_MASK = (byte)0x80;
  95.     static final byte INDEX_MASK = (byte)0x7F;
  96.     private static final int INITIAL_STATE = 1;
  97.     private static final int END_STATE = 0;
  98.     private byte data[];
  99.     private int cols;
  100. }
  101.  
  102.